package com.example.blog.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blog.base.PageRequestDto;
import com.example.blog.base.PageResult;
import com.example.blog.base.Result;
import com.example.blog.entity.Favorites;
import com.example.blog.entity.vo.article.ArticleListVO;
import com.example.blog.entity.vo.favorites.FavoritesDetailInfoVO;
import com.example.blog.entity.vo.favorites.ListEleVO;
import com.example.blog.service.FavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收藏模块
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author wlh
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/blog/favorites")
public class FavoritesController {

    @Autowired
    private FavoritesService favoritesService;


    /**
     * 添加收藏
     * @param ffIds 收藏夹ID
     * @param articleId 文章id集合
     * @return
     */
    @PostMapping("/add")
    public Result<Void> add(@RequestParam("ffIds") List<Long> ffIds, @RequestParam("articleId") Long articleId) {
        favoritesService.add(ffIds, articleId);
        return Result.success();
    }

    /**
     * 取消收藏
     * @param ffId 收藏夹ID
     * @param articleId 文章id
     * @return
     */
    @PostMapping("/del/{ffId}/{articleId}")
    public Result<Void> del(@PathVariable Long ffId, @PathVariable Long articleId) {
        favoritesService.del(ffId, articleId);

        return Result.success();
    }


    /**
     * 收到的收藏通知列表
     * @param pageRequestDto
     * @return
     */
    @PostMapping("/page-list")
    public PageResult<FavoritesDetailInfoVO> pageList(@RequestBody @Validated PageRequestDto pageRequestDto) {
        Page<FavoritesDetailInfoVO> page = favoritesService.pageList(pageRequestDto);
        return PageResult.format(page);
    }

    /**
     * 将未读更新为已读
     * @return
     */
    @PutMapping("/read")
    public Result<Void> read() {
        favoritesService.read();
        return Result.success();
    }
}
